#include"SeqList.h"

void SeqListInit(SL* ps) {
	assert(ps);
	ps->a = (SL*)malloc(sizeof(SL) * 10);
	ps->size = 0;
	ps->space = 10;
}


void SeqListDestroy(SL* ps) {
	assert(ps);
	free(ps->a);
	ps->size = 0;
	ps->space = 0;
}

void SeqListPrint(SL* ps) {
	assert(ps);
	int i = 0;
	for (i = 0; i < ps->size; i++) {
		printf("%d ", ps->a[i]);
	}
	printf("\n");
}

void SeqListCheck(SL* ps) {
	assert(ps);
	if (ps->size+1 >= ps->space) {
		SL* p = realloc(ps, ps->space * 2);
		ps = p;
	}
	ps->space *= 2;
}

int SeqListFind(SL* ps, SLDateType x) {
	int i = 0;
	for (i = 0; i < ps->size; i++) {
		if (ps->a[i] == x) {
			printf("%d  ", i);
		}
	}
	printf("\n");
}

void SeqListInsert(SL* ps, int pos, SLDateType x) {
	int i = ps->size;
	SeqListCheck(ps);
	while (i > pos) {
		ps->a[i] = ps->a[i - 1];
		i--;
	}
	ps->a[pos] = x;
	ps->size++;
}

void SeqListErase(SL* ps, int pos) {
	SeqListCheck(ps);
	int i = pos;
	while (i < ps->size-1) {
		ps->a[i] = ps->a[i + 1];
		i++;
	}
	ps->size--;

}

